<template>
  <CartMain :mode="1"/>
</template>

<script setup lang="ts">
import { onShow } from '@dcloudio/uni-app'
import { watch } from 'vue'

import CartMain from './components/CartMain.vue'
import { useCartStore } from '@/stores'


// 购物车存储
const cartStore = useCartStore()

onShow(() => {
  setBadge()
})


// 监控有效商品数量
watch(() => cartStore.validTotal, () => {
  setBadge()
})


// 设置购物车右上角的徽标
const setBadge = () => {
  uni.setTabBarBadge({
    index: 2,
    text: cartStore.validTotal + ''
  })
}
</script>


<style scoped lang="scss">
</style>